home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Portable Patmos 1.1 / patmos-src / src / close.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-19  |  823 b   |  46 lines  |  [TEXT/KAHL]

  1. #include <sys/types.h>
  2. #include <sys/syslimits.h>
  3. #include <fcntl.h>
  4. #include "crtlocal.h"
  5.  
  6. int close(int fd)
  7.     {
  8.     int res = -1;
  9.     short refnum = crt_fd_tab[fd].fd;
  10.     int i;
  11.     if (crt_fd_tab[fd].flags & O_PIPE)
  12.         {
  13.         free(crt_fd_tab[fd].fd);
  14.         crt_fd_tab[fd].flags = 0;
  15.         refnum = 0;
  16.         }
  17.     if (crt_fd_tab[fd].flags & O_CATALOG)
  18.         {
  19.         crt_fd_tab[fd].flags = 0;
  20.         refnum = 0;
  21.         }
  22.     for (i = 0; i < OPEN_MAX; i++)
  23.         if ((i != fd) && (refnum == crt_fd_tab[i].fd)) res = i;
  24.     if ((res == -1) && refnum)
  25.             {
  26.             FCBPBRec pb;
  27.             pb.ioRefNum = refnum;
  28.             pb.ioCompletion = 0;
  29.             pb.ioVRefNum = crt_ioVRefNum;
  30.             PBCloseSync((ParmBlkPtr)&pb);
  31.             res = pb.ioResult;
  32.             }
  33.     else res = refnum;
  34.     crt_fd_tab[fd].fd = 0;
  35.     return res;
  36.     }
  37.  
  38. void closeall(void)
  39.     {
  40.     int i;
  41.     for (i = 0; i < OPEN_MAX; i++)
  42.         {
  43.         if (crt_fd_tab[i].fd) close(i);
  44.         }
  45.     }
  46.